﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Training7
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String filePath = @"D:\Documents\test1.txt";

            try
            {
                using(StreamWriter writer= new StreamWriter(filePath))
                {
                    writer.WriteLine(textBox1.Text);
                }

                

            } catch (Exception ex) { MessageBox.Show(ex.Message); }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            String filePath = @"D:\Documents\test1.txt";

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    String line = reader.ReadToEnd();

                    richTextBox1.Text = line;

                }
            } catch(Exception ex) { MessageBox.Show(ex.Message); }
           
        }
    }
}
